<template>
  <div class="style-editor">
    <el-form label-position="top">
      <!-- 尺寸和位置 -->
      <el-form-item label="尺寸">
        <el-row :gutter="12">
          <el-col :span="12">
            <el-input-number
              v-model="styleValue.width"
              :min="0"
              placeholder="宽度"
              @change="updateStyle" />
          </el-col>
          <el-col :span="12">
            <el-input-number
              v-model="styleValue.height"
              :min="0"
              placeholder="高度"
              @change="updateStyle" />
          </el-col>
        </el-row>
      </el-form-item>

      <!-- 边距 -->
      <el-form-item label="边距">
        <el-row :gutter="12">
          <el-col :span="12">
            <el-input-number
              v-model="styleValue.margin"
              :min="0"
              placeholder="外边距"
              @change="updateStyle" />
          </el-col>
          <el-col :span="12">
            <el-input-number
              v-model="styleValue.padding"
              :min="0"
              placeholder="内边距"
              @change="updateStyle" />
          </el-col>
        </el-row>
      </el-form-item>

      <!-- 字体样式 -->
      <el-form-item label="字体">
        <el-row :gutter="12">
          <el-col :span="12">
            <el-input-number
              v-model="styleValue.fontSize"
              :min="12"
              :max="72"
              placeholder="字号"
              @change="updateStyle" />
          </el-col>
          <el-col :span="12">
            <el-select
              v-model="styleValue.fontWeight"
              placeholder="字重"
              @change="updateStyle">
              <el-option label="正常" value="normal" />
              <el-option label="加粗" value="bold" />
            </el-select>
          </el-col>
        </el-row>
      </el-form-item>

      <!-- 颜色 -->
      <el-form-item label="颜色">
        <el-row :gutter="12">
          <el-col :span="12">
            <el-color-picker
              v-model="styleValue.color"
              show-alpha
              @change="updateStyle" />
          </el-col>
          <el-col :span="12">
            <el-color-picker
              v-model="styleValue.backgroundColor"
              show-alpha
              @change="updateStyle" />
          </el-col>
        </el-row>
      </el-form-item>

      <!-- 边框 -->
      <el-form-item label="边框">
        <el-row :gutter="12">
          <el-col :span="8">
            <el-input-number
              v-model="styleValue.borderWidth"
              :min="0"
              placeholder="边框宽度"
              @change="updateStyle" />
          </el-col>
          <el-col :span="8">
            <el-select
              v-model="styleValue.borderStyle"
              placeholder="边框样式"
              @change="updateStyle">
              <el-option label="实线" value="solid" />
              <el-option label="虚线" value="dashed" />
              <el-option label="点线" value="dotted" />
            </el-select>
          </el-col>
          <el-col :span="8">
            <el-color-picker
              v-model="styleValue.borderColor"
              show-alpha
              @change="updateStyle" />
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'

const props = defineProps({
  value: {
    type: Object,
    default: () => ({})
  }
})

const emit = defineEmits(['update'])

// 本地样式值
const styleValue = ref({ ...props.value })

// 监听外部值变化
watch(() => props.value, (newVal) => {
  styleValue.value = { ...newVal }
}, { deep: true })

// 更新样式
const updateStyle = () => {
  emit('update', { ...styleValue.value })
}
</script>

<style scoped>
.style-editor {
  padding: 16px;
}
</style> 